package com.yun.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.core.env.Profiles;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.VendorExtension;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

@Configuration
@EnableSwagger2   //开启swagger2
public class SwaggerConfig {

//    分组2
    @Bean
    public Docket docket2(){
        return new Docket (DocumentationType.SWAGGER_2)
                .groupName ("小李同学");
    }

//    配置了swagger的bean实例
//    分组1
    @Bean
    public Docket docket(Environment environment){

//        跑崩了
//        //设置要显示的swagger环境
//        Profiles profiles = Profiles.of("dev","test");
//
//        //通过environment.acceptsProfiles判断是否处在自己设定的环境当中
//        boolean flag = environment.acceptsProfiles(profiles);

        return new Docket (DocumentationType.SWAGGER_2)
                .apiInfo (apiInfo ())
                .groupName ("玛卡巴卡")//分组
                .enable (true)//是否启动swagger，如果为false则在浏览器中不能访问
                .select ()
//                RequestHandlerSelectors------配置扫描接口的方式
//                      basePackage------指定扫描的包
//                      any()  --  扫描全部
//                      none()  -- 都不扫描
//                      withClassAnnotation:扫描类上的注解
//                        withMethodAnnotation : 扫描方法上的注解
                .apis (RequestHandlerSelectors.basePackage ("com.yun.control"))
//                过滤
//                .paths (PathSelectors.ant ("/yun/**"))
                .build ();
    }

//    配置swagger信息 = apiInfo
    public ApiInfo apiInfo(){

//        默认配置信息（页面那些花里胡哨的字）

//        作者信息
        Contact contact = new Contact ("lyj","https://blog.csdn.net/zmgbj","2425767883@qq.com");
        return new ApiInfo("玛卡巴卡的SwaggerAPI文档",
                "I is useless but I ugly",
                "1.0",
                "https://blog.csdn.net/zmgbj",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList<VendorExtension> ());
    }
}
